

set more off
mat drop _all


*** Table D4


use "$path_data/data/temp/main_reg_data_psc.dta", clear



drop if ptsbl_overall_score == .




foreach j in n mean sd {
tabstat have_psc if treatment == 1, stat(`j') save
matrix list r(StatTotal)
matrix `j'_tr1_psc = r(StatTotal)
}

foreach j in n mean sd {
tabstat have_psc if treatment == 0, stat(`j') save
matrix list r(StatTotal)
matrix `j'_ct1_psc = r(StatTotal)
}





*ptu : Psc Take Up

foreach i in have_psc {

	regress `i' treatment, cluster(school_no)

	
	
	matrix ptu1_`i'_post_temp = r(table)
	matrix ptu1_`i'_post_r2 = e(r2)
	matrix ptu1_`i'_post_obs = e(N)

	cgmwildboot_2 `i' treatment, cluster(school_no) bootcluster(school_no) null(0) reps(999) seed(1)
	matrix ptu1_`i'_post_temp_p = e(Pvals)

	
	foreach s in be se pv rpv wpv {
		matrix ptu1_`i'_post_`s' = J(7,1,.)
	}

	foreach j in 1 2 3 4 5 6 7 {
		* beta
		matrix ptu1_`i'_post_be[`j',1] = ptu1_`i'_post_temp[1,`j']
		* standard error
		matrix ptu1_`i'_post_se[`j',1] = ptu1_`i'_post_temp[2,`j']
		* p value
		matrix ptu1_`i'_post_pv[`j',1] = ptu1_`i'_post_temp[4,`j']
		matrix ptu1_`i'_post_wpv[`j',1] = ptu1_`i'_post_temp_p[`j',1]
	}

*	cgmwildboot `i' treatment wrongDT cheating wrongTshort wrongTlong dum_grade, ///
*	cluster(school_no) bootcluster(school_no) null(0 . . . . . ) reps(999) seed(1)


	
}












forvalues n = 1/1 {
forvalues item = 1/2 {
		forvalues scale = 1/1 {
		if ptu`n'_have_psc_post_wpv[`item', `scale']<=0.01 {
			local nancstar`n'_`item'`scale' %3s "***"
		}
		else if (ptu`n'_have_psc_post_wpv[`item', `scale']>0.01) & (ptu`n'_have_psc_post_wpv[`item', `scale']<=0.05) {
			local nancstar`n'_`item'`scale' %2s "**"
		}
		else if (ptu`n'_have_psc_post_wpv[`item', `scale']>0.05) & (ptu`n'_have_psc_post_wpv[`item', `scale']<=0.10) {
			local nancstar`n'_`item'`scale' %1s "*"
		}
		else {
			local nancstar`n'_`item'`scale'  ""
		}
	} // forvalues `scale' loop

}  // forvalues `item' loop


} // forvalues `n' loop





forvalues n = 1/1 {
forvalues item = 1/2 {
		forvalues scale = 1/1 {
		if ptu`n'_have_psc_post_pv[`item', `scale']<=0.01 {
			local ancstar`n'_`item'`scale' %3s "***"
		}
		else if (ptu`n'_have_psc_post_pv[`item', `scale']>0.01) & (ptu`n'_have_psc_post_pv[`item', `scale']<=0.05) {
			local ancstar`n'_`item'`scale' %2s "**"
		}
		else if (ptu`n'_have_psc_post_pv[`item', `scale']>0.05) & (ptu`n'_have_psc_post_pv[`item', `scale']<=0.10) {
			local ancstar`n'_`item'`scale' %1s "*"
		}
		else {
			local ancstar`n'_`item'`scale'  ""
		}
	} // forvalues `scale' loop

}  // forvalues `item' loop


} // forvalues `n' loop












tempname hh2
file open `hh2' using "$pardir/tableD4.tex", write replace
file write `hh2' "" _newline
file write `hh2' "% Date: `c(current_date)'" _newline
file write `hh2' "% Time: `c(current_time)'" _newline
file write `hh2' "" _newline


file write `hh2' "\begin{table}[t!]\footnotesize" _newline
file write `hh2' "  \centering" _newline
file write `hh2' "  \caption{PSC Take-up}" _newline
file write `hh2' "\label{tab:main_psc_takeup_dummy}" _newline
file write `hh2' "\scalebox{0.9}{" _newline
file write `hh2' "\begin{threeparttable}" _newline

file write `hh2' "\begin{tabular}{lcccc}\toprule\midrule" _newline




*file write `hh2' "\cmidrule{2-5} & &&&      \\" _newline

file write `hh2' " Dependent Variable & Treatment &  Control  & Difference & N   \\\midrule" _newline


file write `hh2' "    PSC Take-up   & " %04.3f (mean_tr1_psc[1,1]) " &   " %04.3f (mean_ct1_psc[1,1]) " & " %04.3f (ptu1_have_psc_post_be[1,1]) `ancstar1_11' " & " (ptu1_have_psc_post_obs[1,1]) " \\" _newline
file write `hh2' "    									    & [" %04.3f (sd_tr1_psc[1,1]) "] &   [" %04.3f (sd_ct1_psc[1,1]) "] & (" %04.3f (ptu1_have_psc_post_se[1,1])             ") &                     \\\midrule\bottomrule" _newline


file write `hh2' "\end{tabular}" _newline
file write `hh2' "\end{threeparttable}" _newline
file write `hh2' "}" _newline
file write `hh2' "\label{tab:addlabel}%" _newline
file write `hh2' "\end{table}" _newline

file write `hh2' "" _newline
file write `hh2' "" _newline
file write `hh2' "" _newline
file write `hh2' "" _newline

file close `hh2'





